#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/epoll.h>

#include "socket.h"
#include "like.h"
#include "data_packet.h"

int epoll_init(int size)
{
	int root_fd;
	root_fd = epoll_create(size);
	if(root_fd == -1)
		return -1;
	return root_fd;
	
}
int epoll_ctl_link(int fd,int root_fd,struct epoll_event ep)
{
	int ret;
	ep.data.fd=fd; ep.events=EPOLLIN | EPOLLET;
	ret = epoll_ctl(root_fd,  EPOLL_CTL_ADD, fd, &ep);
	if(ret == -1)
		return -1;
	return 0;
}

int eproot_add_fd(int connfd,int root_fd,struct epoll_event ep)
{
	int ret;
	ep.data.fd=connfd;ep.events=EPOLLIN | EPOLLET;
	ret = epoll_ctl(root_fd,EPOLL_CTL_ADD,connfd,&ep);
	if(ret == -1)
		return -1;
	return 0;
}

void epoll_ctl_del(int sockfd,int root_fd,userinfo *head)
{
	int ret;
	ret = epoll_ctl(root_fd, EPOLL_CTL_DEL, sockfd, NULL);  
		if (ret == -1) 
			perr_exit("epoll_ctl_del error"); 
		close(sockfd);    
}
